package edu.java.water.mapper;

import edu.java.water.entity.CartEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Mapper
@Repository
public interface CartMapper {
    @Select("SELECT * from cart join product on cart.product_id=product.id JOIN norm on cart.norm_id=norm.id where user_id=#{user_id}")
    ArrayList<CartEntity> selectCart(Integer user_id);
    @Update("update cart set product_num=#{product_num} where id=#{id}")
    int setCartNumber(Integer product_num,Integer id);
    @Delete("delete from cart where id=#{id}")
    int deleteCartNumber(Integer id);
    @Select("<script>" +
            "SELECT * from cart join product on cart.product_id=product.id JOIN norm on cart.norm_id=norm.id where user_id=#{user_id} and cart.id in " +
            "<foreach collection='cart_ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    ArrayList<CartEntity> setOrder(Integer user_id,ArrayList<String> cart_ids);
}
